package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.AddSuperviseNoticeDto;
import com.ruoyi.system.domain.updateSuperviseNoticeDto;
import jakarta.servlet.http.HttpServletResponse;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSuperviseHistory;
import com.ruoyi.system.service.ISysSuperviseHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 督查历史记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-31
 */
@RestController
@RequestMapping("/system/history")
public class SysSuperviseHistoryController extends BaseController
{
    @Autowired
    private ISysSuperviseHistoryService sysSuperviseHistoryService;

    /**
     * 查询督查历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSuperviseHistory sysSuperviseHistory)
    {
        startPage();
        List<SysSuperviseHistory> list = sysSuperviseHistoryService.selectSysSuperviseHistoryList(sysSuperviseHistory);
        return getDataTable(list);
    }

    /**
     * 导出督查历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:history:export')")
    @Log(title = "督查历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSuperviseHistory sysSuperviseHistory)
    {
        List<SysSuperviseHistory> list = sysSuperviseHistoryService.selectSysSuperviseHistoryList(sysSuperviseHistory);
        ExcelUtil<SysSuperviseHistory> util = new ExcelUtil<SysSuperviseHistory>(SysSuperviseHistory.class);
        util.exportExcel(response, list, "督查历史记录数据");
    }

    /**
     * 获取督查历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:history:query')")
    @GetMapping(value = "/{historyId}")
    public AjaxResult getInfo(@PathVariable("historyId") Long historyId)
    {
        return success(sysSuperviseHistoryService.selectSysSuperviseHistoryByHistoryId(historyId));
    }

    /**
     * 新增督查历史记录
     */
    @PreAuthorize("@ss.hasPermi('system:history:add')")
    @Log(title = "督查历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSuperviseHistory sysSuperviseHistory)
    {
        return toAjax(sysSuperviseHistoryService.insertSysSuperviseHistory(sysSuperviseHistory));
    }

    /**
     * 修改督查历史记录
     */
    @PreAuthorize("@ss.hasPermi('system:history:edit')")
    @Log(title = "督查历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSuperviseHistory sysSuperviseHistory)
    {
        return toAjax(sysSuperviseHistoryService.updateSysSuperviseHistory(sysSuperviseHistory));
    }

    /**
     * 删除督查历史记录
     */
    @PreAuthorize("@ss.hasPermi('system:history:remove')")
    @Log(title = "督查历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{historyIds}")
    public AjaxResult remove(@PathVariable Long[] historyIds)
    {
        return toAjax(sysSuperviseHistoryService.deleteSysSuperviseHistoryByHistoryIds(historyIds));
    }


    @PostMapping("/add_problem_notice")
    public AjaxResult addProblemNotice(@RequestBody AddSuperviseNoticeDto dto){
        return sysSuperviseHistoryService.addProblemNotice(dto);
    }

    @PostMapping("/update_problem_notice")
    public AjaxResult updateProblemNote(@RequestBody updateSuperviseNoticeDto dto){
        return sysSuperviseHistoryService.updateProblemNote(dto);
    }

}
